/* graph.h
Desc.: Implementation of a simple graph class
Auth.: Ashwin Lall
Start: January 6, 2014
*/

#ifndef _GRAPH_H
#define _GRAPH_H

#include <map>
#include <set>
#include <string>
using namespace std;

class Graph
{
public:
    // constructors
    Graph();
    Graph(string filename);    

    // accessors
    set<int> getNodes();
    set<int> getNeighbors(int node);
    int numNodes();
    int numEdges();
    bool hasEdge(int node1, int node2);
    int getDegree(int node);
    void printGraph();

    // modifiers
    void addNode(int node);
    void addEdge(int node1, int node2);
    void removeEdge(int node1, int node2);
    void removeNode(int node);
    void readGraph(string filename);
    void readUndirectedGraph(string filename);
    void reset();

protected:
    int _numNodes, _numEdges;    // number of nodes and edges for efficiency
    set<int> _nodes;             // set of node IDs
    map<int, set<int> > _edges;  // map from each node to its set of adjacent nodes
};

#endif
